CheckParforJavaPaths.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. %=============================================%
  2. % Make sure each worker has java paths added. %
  3. % Note: Required for parfor progress bar. %
  4. % Last modified: Sept. 7, 2014 %
  5. %=============================================%
  6. % Copyright (C) 2013-2014, Michael J. Cheung
  7. %
  8. % This file is a part of the MEG & PLS Pipeline (MEGPLS). For more
  9. % details, see the documentation included with the software package.
  10. %
  11. % MEGPLS is free software: you can redistribute it and/or modify it under
  12. % the terms of the GNU General Public License version 2 as published by
  13. % the Free Software Foundation. This program is distributed in the hope
  14. % that it will be useful, but WITHOUT ANY WARRANTY; without even the
  15. % implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. % See the GNU General Public License for more details.
  17. %
  18. % You should have received a copy of the GNU General Public License along
  19. % with this program. If not, you can download the license here:
  20. % <http://www.gnu.org/licenses/old-licenses/gpl-2.0>.
  21. function Success = CheckParforJavaPaths
  22. CurrentRunDir = pwd;
  23. [PipelineDir, ~, ~] = fileparts(which('DriverGUI.m'));
  24. JavaFolder = [PipelineDir,'/MEGPLS_COMPONENTS/MatlabFileExchange/parforprogress/java'];
  25. if ~exist(JavaFolder, 'dir')
  26. message = {'ERROR:'; '';
  27. 'Could not find java functions folder for the parfor progress bar.';
  28. 'Progress bar will be disabled.'; ''};
  29. msgbox(message, 'ERROR:')
  30. Success = 0;
  31. return;
  32. end
  33. Toolboxes = ver;
  34. if any(strcmp('Parallel Computing Toolbox', {Toolboxes.Name}))
  35. if matlabpool('size') == 0
  36. javaaddpath(JavaFolder);
  37. else
  38. cd(JavaFolder);
  39. pctRunOnAll javaaddpath(pwd)
  40. cd(CurrentRunDir);
  41. end
  42. else
  43. javaaddpath(JavaFolder);
  44. end
  45. Success = 1;